import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

# Given data
data = {
    'Method': ['EMReg', 'ssEMnet', 'Ours'] * 3,
    'Dataset': ['CREMI0.2', 'CREMI0.2', 'CREMI0.2',
                'CREMI0.25', 'CREMI0.25', 'CREMI0.25',
                'CREMI0.3', 'CREMI0.3', 'CREMI0.3'],
    'Dice Score': [0.88726, 0.78095, 0.92663,
                   0.83334, 0.71095, 0.87864,
                   0.70465, 0.59095, 0.86293],
    'SSIM': [0.77310, 0.66820, 0.80355,
             0.71994, 0.60820, 0.74517,
             0.59898, 0.51820, 0.72403],
    'NCC': [0.66806, 0.50159, 0.74199,
            0.61697, 0.42159, 0.65753,
            0.54386, 0.33159, 0.62250]
}

# Transform data to a long format
df_long = pd.DataFrame(data)
df_long = pd.melt(df_long, id_vars=['Method', 'Dataset'], var_name='Metric', value_name='Value')

# Change the order of the methods
method_order = ['Ours', 'EMReg', 'ssEMnet']
df_long['Method'] = pd.Categorical(df_long['Method'], categories=method_order, ordered=True)

# Plot setup
# sns.set(style="whitegrid")
sns.set_context("talk")
fig, axes = plt.subplots(1, 3, figsize=(18, 6), sharey=True)

# Create a barplot for each metric
for i, metric in enumerate(['Dice Score', 'SSIM', 'NCC']):
    sns.barplot(x='Dataset', y='Value', hue='Method', data=df_long[df_long['Metric'] == metric], ax=axes[i], ci=None)
    axes[i].set_title(metric)
    axes[i].set_ylim(0.3, 1)  # Set the limit for the Y-axis starting from 0.4

# Adjust layout
plt.tight_layout()
plt.savefig('C:\\Users\\crxc\\Pictures\\wandb\\论文2\\图表\\b.png', bbox_inches='tight')

# Show the plot
plt.show()
